/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PanelCrearPaciente.java
 *
 * Created on 11/01/2012, 04:55:25 AM
 */
package co.edu.eam.clinica.vista.gui.paciente;

import co.edu.eam.clinica.vista.controladores.paciente.controladorPanelCrearPaciente;
import co.edu.eam.clinica.vista.gui.consulta.*;
import co.edu.eam.clinica.vista.gui.common.BotonOncologos;
import co.edu.eam.clinica.vista.gui.common.PanelOncologos;
import co.edu.eam.persitencia.entidades.Acudiente;
import co.edu.eam.persitencia.entidades.Ciudad;
import co.edu.eam.persitencia.entidades.EPS;
import co.edu.eam.persitencia.entidades.Paciente;
import co.edu.eam.persitencia.entidades.Telefono;
import co.edu.eam.persitencia.enumeraciones.SexoEnum;
import co.edu.eam.persitencia.enumeraciones.TipoDocumentoEnum;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Camilo Andres
 */
public class PanelCrearPaciente extends PanelOncologos {

    private controladorPanelCrearPaciente controladorPanel;

    public PanelCrearPaciente(String documento) {
        initComponents();
        try {
            llenarCombos();
        } catch (Exception ex) {
            Logger.getLogger(PanelCrearPaciente.class.getName()).log(Level.SEVERE, null, ex);
        }



        if (documento != null) {

            try {
                Paciente llego = controladorPanel.buscarPaciente(documento);
                tfNombre.setText(llego.getPrimerNombre());
                tfSegundoNOmbre.setText(llego.getSegundoNombre());
                tfApellido.setText(llego.getPrimerApellido());
                tfSegundoApellido.setText(llego.getSegundoApellido());
                tfDireccion.setText(llego.getDireccion());
                cbTipoDoc.setSelectedItem(llego.getTipoDocumento());
                tfEmail.setText(llego.getEmail());
                dcFechaNac.setDate(llego.getFechaNacimiento());
                cbCiudades.setSelectedItem(llego.getCiudad());
                cbEPS.setSelectedItem(llego.getEps());
                SexoEnum ses = llego.getSexo();
                if (ses.equals(SexoEnum.FEMENINO)) {

                    rbFemenino.setSelected(true);

                } else {
                    rbMAsculino.setSelected(true);
                }




                tfTelefono.setText(contar(llego.getTelefonos()));

                llenarTablaAcudiente(llego.getAcudientes());
            } catch (Exception ex) {
                Logger.getLogger(PanelCrearPaciente.class.getName()).log(Level.SEVERE, null, ex);
            }

        }


    }

    /**
     * me llena todos los combos de la ventana PanelCrearPaciente
     *
     * @throws Exception
     */
    public void llenarCombos() throws Exception {


        TipoDocumentoEnum[] documentos = TipoDocumentoEnum.values();
        List<Ciudad> ciudades = controladorPanel.listarCiudades();
        List<EPS> epss = controladorPanel.listarEps();

        for (int i = 0; i < documentos.length; i++) {
            cbTipoDoc.addItem(documentos[i]);
        }

        for (int w = 0; w < ciudades.size(); w++) {
            cbCiudades.addItem(w);
        }

        for (int d = 0; d < epss.size(); d++) {
            cbEPS.addItem(d);
        }

    }
    /*
     * llena la tabla con los acudientes que tiene un paciente 
     */

    public void llenarTablaAcudiente(List<Acudiente> j) {

        List<Acudiente> lista = j;

        DefaultTableModel modelo = (DefaultTableModel) jTable1.getModel();
        modelo.setRowCount(lista.size());

        for (int i = 0; i < lista.size(); i++) {
            modelo.setValueAt(lista.get(i).getDocumento(), i, 0);
            modelo.setValueAt(lista.get(i).getNombre(), i, 1);
            modelo.setValueAt(lista.get(i).getPrimerApellido(), i, 2);
            modelo.setValueAt(lista.get(i).getEmail(), i, 3);


        }

    }

    /*
     * añida todos los telefonos de un paciente
     */
    public String contar(List<Telefono> tas) {
        String s = "-";
        for (Telefono telefono : tas) {
            s = telefono.getNumero() + s;
        }



        return s;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        bttnGuardarPaciente = new javax.swing.JButton();
        bttnbuscar = new javax.swing.JButton();
        bttnEditar = new javax.swing.JButton();
        bttnEliminar = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        tfApellido = new javax.swing.JTextField();
        dcFechaNac = new com.toedter.calendar.JDateChooser();
        tfNombre = new javax.swing.JTextField();
        cbTipoDoc = new javax.swing.JComboBox();
        rbFemenino = new javax.swing.JRadioButton();
        jLabel3 = new javax.swing.JLabel();
        rbMAsculino = new javax.swing.JRadioButton();
        jLabel10 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        cbEPS = new javax.swing.JComboBox();
        tfDocumento = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        tfSegundoApellido = new javax.swing.JTextField();
        tfSegundoNOmbre = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        tfEmail = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        cbCiudades = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        tfTelefono = new javax.swing.JTextField();
        tfDireccion = new javax.swing.JTextField();

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Acudientes"));

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Documento", "Nombre", "Apellido", "Telefono"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                true, true, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTable1);

        bttnGuardarPaciente.setText("Guardar");
        bttnGuardarPaciente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bttnGuardarPacienteActionPerformed(evt);
            }
        });

        bttnbuscar.setText("Buscar");
        bttnbuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bttnbuscarActionPerformed(evt);
            }
        });

        bttnEditar.setText("Editar");

        bttnEliminar.setText("Eliminar");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 578, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(bttnGuardarPaciente)
                        .addGap(29, 29, 29)
                        .addComponent(bttnbuscar)
                        .addGap(39, 39, 39)
                        .addComponent(bttnEditar)
                        .addGap(44, 44, 44)
                        .addComponent(bttnEliminar)
                        .addGap(0, 0, Short.MAX_VALUE))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bttnGuardarPaciente)
                    .addComponent(bttnbuscar)
                    .addComponent(bttnEditar)
                    .addComponent(bttnEliminar))
                .addGap(37, 37, 37))
        );

        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel12.setText("EPS");

        jLabel9.setText("Tipo");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel2.setText("Primer Apellido");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel5.setText("Fecha Nacimiento");

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel11.setText("Segundo Nombre");

        buttonGroup1.add(rbFemenino);
        rbFemenino.setText("Femenino");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel3.setText("Direccion");

        buttonGroup1.add(rbMAsculino);
        rbMAsculino.setText("Masculino");

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel10.setText("Segundo Apellido");

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel6.setText("Sexo");

        cbEPS.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbEPSActionPerformed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel4.setText("Email");

        tfSegundoNOmbre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfSegundoNOmbreActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel1.setText("Primer Nombre");

        jLabel8.setText("Documento");

        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel13.setText("Ciudad");

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel7.setText("Telefono");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel13)
                            .addComponent(jLabel7))
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(51, 51, 51)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(cbCiudades, javax.swing.GroupLayout.PREFERRED_SIZE, 243, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(tfDocumento, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jLabel9)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(cbTipoDoc, javax.swing.GroupLayout.PREFERRED_SIZE, 294, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(52, 52, 52)
                                .addComponent(tfDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, 482, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(jLabel8)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(tfApellido)
                            .addComponent(tfNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel10)
                            .addComponent(jLabel11))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(tfSegundoApellido, javax.swing.GroupLayout.DEFAULT_SIZE, 235, Short.MAX_VALUE)
                            .addComponent(tfSegundoNOmbre)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addGap(73, 73, 73))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tfEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 243, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cbEPS, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(dcFechaNac, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addGap(73, 73, 73)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tfTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, 362, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(rbMAsculino)
                                .addGap(18, 18, 18)
                                .addComponent(rbFemenino)))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(tfDocumento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(cbTipoDoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(tfNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfSegundoNOmbre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11))
                .addGap(8, 8, 8)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tfApellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(tfSegundoApellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel10))
                        .addGap(2, 2, 2)))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(17, 17, 17)
                        .addComponent(jLabel3))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(tfDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(11, 11, 11)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel13)
                    .addComponent(cbCiudades, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel4)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(tfEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel5))
                    .addComponent(dcFechaNac, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbEPS, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel6))
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(rbMAsculino)
                        .addComponent(rbFemenino)))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(tfTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void bAgregarAcudienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bAgregarAcudienteActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_bAgregarAcudienteActionPerformed

    private void bAgregarTelefonooActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bAgregarTelefonooActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_bAgregarTelefonooActionPerformed

    private void tfSegundoNOmbreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfSegundoNOmbreActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_tfSegundoNOmbreActionPerformed

    private void bGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bGuardarActionPerformed
    }//GEN-LAST:event_bGuardarActionPerformed

    private void bEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bEditarActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_bEditarActionPerformed

    private void bBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bBuscarActionPerformed
        // TODO add your handling code here:
        // TODO add your handling code here:
    }//GEN-LAST:event_bBuscarActionPerformed

    private void bttnGuardarPacienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bttnGuardarPacienteActionPerformed
        // TODO add your handling code here:

        try {
            if (tfDocumento.getText().equals("")) {
                tfDocumento.requestFocus();
                JOptionPane.showMessageDialog(this, "POR FAVOR DIGITE EL DOCUMENTO DEL PACIENTE");
            } else {
                if (tfNombre.getText().equals("")) {
                    tfNombre.requestFocus();
                    JOptionPane.showMessageDialog(this, "POR FAVOR DIGITE EL PRIMER NOMBRE DEL PACIENTE");
                } else {
                    if (tfSegundoNOmbre.getText().equals("")) {
                        JOptionPane.showMessageDialog(this, "POR FAVOR DIGITE EL SEGUNDO NOMBRE DEL PACIENTE");
                        tfSegundoNOmbre.requestFocus();
                    } else {
                        if (tfApellido.getText().equals("")) {
                            JOptionPane.showMessageDialog(this, "POR FAVOR DIGITE EL PRIMER APELLIDO  DEL PACIENTE");
                            tfApellido.requestFocus();
                        } else {
                            if (tfDireccion.getText().equals("")) {
                                JOptionPane.showMessageDialog(this, "POR FAVOR DIGITE LA DIRECCION  DEL PACIENTE");
                                tfDireccion.requestFocus();
                            } else {
                                if (tfEmail.getText().equals("")) {
                                    JOptionPane.showMessageDialog(this, "POR FAVOR DIGITE EL EMAIL  DEL PACIENTE");
                                    tfEmail.requestFocus();
                                } else {
                                    String documento = tfDocumento.getText();
                                    Enum tipo = (TipoDocumentoEnum) cbTipoDoc.getSelectedItem();
                                    String primerNombre = tfNombre.getText();
                                    String segundoNombre = tfSegundoNOmbre.getText();
                                    String primerApellido = tfApellido.getText();
                                    String segundoApellido = tfSegundoApellido.getText();
                                    String direccion = tfDireccion.getText();
                                    String ciudad = (String) cbCiudades.getSelectedItem();
                                    String email = tfEmail.getText();
                                    Date fecha = dcFechaNac.getDate();
                                    String eps = (String) cbEPS.getSelectedItem();
                                    /////////////////////////
                                    SexoEnum sexo;

                                    if (rbFemenino.isSelected()) {
                                        sexo = SexoEnum.FEMENINO;
                                    } else {
                                        sexo = SexoEnum.MASCULINO;
                                    }
                                    //////////////////////////
                                    Enum sex = sexo;
                                    int telefono = Integer.parseInt(tfTelefono.getText());
                                    Paciente nuevop = new Paciente(documento, primerNombre, segundoNombre, primerApellido, segundoApellido, TipoDocumentoEnum.PASAPORTE, direccion, email, sexo, null, direccion);

                                    Paciente b = controladorPanel.buscarPaciente(documento);

                                    if (b == null) {
                                        controladorPanel.crearPaciente(nuevop);
                                        JOptionPane.showMessageDialog(this, "PACIENTE CREADO");

                                    } else {
                                        JOptionPane.showMessageDialog(this, "PACIENTE YA EXISTE");
                                    }
                                }
                            }
                        }
                    }
                }
            }



        } catch (Exception ex) {
            Logger.getLogger(PanelCrearPaciente.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_bttnGuardarPacienteActionPerformed

    private void cbEPSActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbEPSActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cbEPSActionPerformed

    private void bttnbuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bttnbuscarActionPerformed
        // TODO add your handling code here:
        try {
            if (tfDocumento.getText().equals("")) {
                JOptionPane.showMessageDialog(this, "INGRESE EL DOCUMENTO");
                tfDocumento.requestFocus();
            } else {

                String doc = tfDocumento.getText();

                Paciente jas = controladorPanel.buscarPaciente(doc);

                if (jas != null) {
                    tfNombre.setText(jas.getPrimerNombre());
                    tfSegundoNOmbre.setText(jas.getSegundoNombre());
                    tfApellido.setText(jas.getPrimerApellido());
                    tfSegundoApellido.setText(jas.getSegundoApellido());
                    tfDireccion.setText(jas.getDireccion());
                    cbTipoDoc.setSelectedItem(jas.getTipoDocumento());
                    tfEmail.setText(jas.getEmail());
                    //falta fecha
                    cbCiudades.setSelectedItem(jas.getCiudad());
                    cbEPS.setSelectedItem(jas.getEps());
                    SexoEnum ses = jas.getSexo();
                    if (ses.equals(SexoEnum.FEMENINO)) {

                        rbFemenino.setSelected(true);

                    } else {
                        rbMAsculino.setSelected(true);
                    }




                    tfTelefono.setText(contar(jas.getTelefonos()));


                } else {
                    JOptionPane.showMessageDialog(this, "EL PACIENTE NO EXISTE");
                }
            }
        } catch (Exception ex) {
            Logger.getLogger(PanelCrearPaciente.class.getName()).log(Level.SEVERE, null, ex);
        }








    }//GEN-LAST:event_bttnbuscarActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bttnEditar;
    private javax.swing.JButton bttnEliminar;
    private javax.swing.JButton bttnGuardarPaciente;
    private javax.swing.JButton bttnbuscar;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JComboBox cbCiudades;
    private javax.swing.JComboBox cbEPS;
    private javax.swing.JComboBox cbTipoDoc;
    private com.toedter.calendar.JDateChooser dcFechaNac;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JRadioButton rbFemenino;
    private javax.swing.JRadioButton rbMAsculino;
    private javax.swing.JTextField tfApellido;
    private javax.swing.JTextField tfDireccion;
    private javax.swing.JTextField tfDocumento;
    private javax.swing.JTextField tfEmail;
    private javax.swing.JTextField tfNombre;
    private javax.swing.JTextField tfSegundoApellido;
    private javax.swing.JTextField tfSegundoNOmbre;
    private javax.swing.JTextField tfTelefono;
    // End of variables declaration//GEN-END:variables
}
